var maxArea = function(height) {
  const len = height.length;
  let left = 0, right = len - 1, ans = 0;

  while (left < right) {
    let area = Math.min(height[left], height[right]) * (right - left);
    ans = Math.max(ans, area);
    if (height[left] < height[right]) {
      left++;
    } else {
      right--;
    }
  }
  return ans;
}

const height = [1,8,6,2,5,4,8,3,7];
console.log(maxArea(height))